<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="author" content="LF">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<body>
    <button id="btn">按钮</button>

<script>
    onload = function(){
        const btn = document.getElementById('btn')
       /*  btn.onclick = function(){
            //this.style.backgroundColor = 'red'
            setTimeout(function(){
                this.style.backgroundColor = 'red'
            },1000)
        } 
        setTimeout(function(){
                this.style.backgroundColor = 'red'
            },1000)
            默认为
            window.setTimeout(function(){
                this.style.backgroundColor = 'red'
            },1000)
            } 
            this指向的是window，用es（）匿名函数，指向为当前方法this，箭头函数找外一层的this
        */
        btn.onclick = function(){
            setTimeout(()=>{
                this.style.backgroundColor = 'red'
            },1000)
        }
    }
</script>
</body>
</html>